﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Manyor.Net;
using System.IO;

namespace Manyor.Server
{
    class Program
    {
        static SocketServer server;
        static FileStream fs;
        static int counter = 0;
        static void Main(string[] args)
        {
            //new ClientFileTransfer().ReadyTransferFile("fdsf","fsdfsdf");
            server  = new SocketServer(new Action<byte[],int>(ReceiverMessage));
            server.StartServer();
            File.Delete("1.jpg");
            fs=new FileStream("1.jpg", FileMode.OpenOrCreate,FileAccess.Write);
            Console.ReadLine();
        }

      
        public static void ReceiverMessage(byte[] bytes, int length)
        {
            if (bytes[0] == 0)
            {
                fs.Write(bytes, NetConfig.HEADER_SIZE, length - NetConfig.HEADER_SIZE);
            }
            else
            {
                fs.Write(bytes, NetConfig.HEADER_SIZE, length - NetConfig.HEADER_SIZE);
                fs.Flush();
                fs.Close();
            }
        }
    }
}
